<template>
	<view class="content">
		<mescroll-uni ref="mescrollRef" @init="mescrollInit"  @up="upCallback" :up="upOption" :down="{use: false}">
		<view class="section-0">
			<view class="section-body">
				<view class="progress">
					<view class="top">
						<view class="left">{{analysis.project_amount_total}}<text>/{{analysis.project_budget_total}}万元</text></view>
						<view class="right">{{analysis.fee}}%</view>
					</view>
					<view class="bottom">
						<view  class="value" :style="{width: `${analysis.fee}%`}">
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="section-1">
			<view class="form">
				<view class="form-item">
					<view class="label">项目名称</view>
					<view class="shape"></view>
					<view class="input">
						<u--input
							placeholderClass="input-placeholder"
							class="input-body"
						    v-model="form.projectName"
						  ></u--input>
					</view>
				</view>
				<!-- <view class="form-item form-item-status">
					<view class="label">预算完成情况</view>
					<view class="shape"></view>
					<view class="input">
						<u--input
							placeholderClass="input-placeholder"
							class="input-body"
						    v-model="form.start"
							type="number"
						  ></u--input>
						  <view class="time-split">-</view>
						  <u--input
						  	placeholderClass="input-placeholder"
						  	class="input-body"
							v-model="form.end"
							type="number"
						    ></u--input>
					</view>
				</view> -->
				<view class="actions">
					<view class="action" @click="handleResetForm()">
						<text>重</text>
						<text>置</text>
					</view>
					<view class="action search" @click="handleSearch()">
						<text>查</text>
						<text>询</text>
					</view>
				</view>
			</view>
			<view class="list">
				<view class="item" v-for="(item, idx) in list" :key="item.id">
					<view class="top">
						<view class="name">
							{{idx + 1}}.{{item.project_name}}
						</view>
						<view class="info">
							<text>预算总金额：{{item.project_budget}}万元</text>
							<text>预算完成比例：{{item.budget_rate}}</text>
						</view>
						<view class="info">
							<text>预算完成情况：{{item.budget_margin}}万元</text>
							<text>预算差额：{{item.budget_percent}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import { budgetAnalysisApi,budgetApi } from '@/api/project.js';
	import { mapGetters, mapActions} from 'vuex';
	export default {
		data() {
			return {
				form: {
					projectName: '',
				},
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				upOption:{
					textNoMore: '-- 没有更多了 --'
				},
				analysis: {},
				pageSize:20,
				list: []
			};
		},
		methods: {
			/*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			async budgetAnalysisApi() {
				uni.showLoading({title: '加载中...'});
				const { data } = await budgetAnalysisApi({
					...this.form,
				});
				// console.log('666666',data)
				uni.hideLoading();
				if (data.code === 1) {
					// this.projectRiskApi()
					this.analysis = data.data;
					console.log(this.analysis,21312);
				}
			},
			
			/*上拉加载的回调*/
			async upCallback(page) {
				let {data} =  await budgetApi({
					...this.form,
					page: page.num,
					pageSize: this.pageSize
				});
				
				if (data.code === 1 && data.data.length != 0) {				
					// 接口返回的当前页数据列表 (数组)
					let arr = [];
					for (let key in data.data.data) {
						arr.push(data.data.data[key]);
					}
					let curPageData = arr; 
					// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
					let curPageLen = curPageData.length; 
					// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
					let totalPage = data.data.data.last_page; 
					//设置列表数据
					if(page.num == 1) this.list = []; //如果是第一页需手动置空列表
					this.list = this.list.concat(curPageData); //追加新数据
					// 请求成功,隐藏加载状态
					this.mescroll.endByPage(curPageLen, totalPage); 
					setTimeout(()=>{
						this.mescroll.endSuccess(curPageLen);
						// this.mescroll.endSuccess(1);
					},20);
				} else{
					//  请求失败,隐藏加载状态
					this.mescroll.endErr()
				}
			},
			handleResetForm(){
				for (let key in this.form) {
					this.form[key] = '';
				}
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0,0);
			},
			handleSearch(){
				this.budgetAnalysisApi();
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0,0);
			},
			onReady() {
				this.budgetAnalysisApi();
				// this.fetchData();
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		background-color: #fff;
	}
	.section-1{
		position: relative;
		top: -50rpx;
		z-index: 10;
		background-color: #fff;
		border-top-left-radius: 50rpx;
		border-top-right-radius: 50rpx;
		.list{
			width: 670rpx;
			box-sizing: border-box;
			margin-left: 40rpx;
			border-top: 2rpx solid #d8e4f2;
			.item{
				width: 100%;
				border-bottom: 2rpx solid #e3e8f5;
						
				&:last-child {
					border-bottom: none;
				}
						
				.top {
					width: 100%;
					overflow: hidden;
					padding-top: 20rpx;
					padding-bottom: 10rpx;
						
					.name {
						float: left;
						width: 620rpx;
						height: 50rpx;
						line-height: 50rpx;
						color: #3b3c40;
						font-size: 26rpx;
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
					}
						
					.info {
						width: 100%;
						float: left;
						height: 24rpx;
						line-height: 24prx;
						font-size: 16rpx;
						color: #7f98ae;
						margin-bottom: 8rpx;
						
						text {
							margin-right: 30rpx;
						
							&:last-child {
								margin-right: 0;
							}
						}
					}
				}
				
			}
		}
		.actions{
			width: 100%;
			height: 50rpx;
			margin-top: 29rpx;
			padding-bottom: 40rpx;
			display: flex;
			justify-content: space-between;
			.action{
				width: 288rpx;
				height: 48rpx;
				background-color: #395cf5;
				border-radius: 20rpx;
				text-align: center;
				line-height: 48rpx;
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				color: #ffffff;
				text{
					&:first-child{
						margin-right: 20rpx;
					}
				}
			}
			.search{
				background-color: #1534ce;
			}
		}
		.form{
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;
			.form-item{
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 34rpx;
				@include clear();
				.label{
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 48rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}
				.shape{
					width: 3rpx;
					height: 32rpx;
					background-color: #7f98ae;
					float: left;
					margin-top: 8rpx;
				}
				.input{
					float: left;
					width: calc(100% - 134rpx - 3rpx);
					.input-body{
						box-sizing: border-box;
						width: 100%;
						height: 48rpx;
						padding: 0!important;
						border: none;
						padding-left: 30rpx!important;
						padding-right: 30rpx!important;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.7);
						line-height: 48rpx;
					}
					.input-placeholder{
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.5);
					}
				}	
			}
			.form-item-status{
				.label{
					width: 192rpx;
				}
				.input{
					width: calc(100% - 192rpx - 3rpx);
					.input-body{
						width: 45%;
						float: left;
					}
					.time-split {
						float: left;
						width: 10%;
						text-align: center;
						color: #1534ce;
						line-height: 44rpx;
					}
				}
			}
		}
	}
	.section-0{
		width: 100%;
		background-color: #2e5efe;
		.section-body{
			width: 100%;
			padding-left: 40rpx;
			height: 150rpx;
			padding-right: 40rpx;
			padding-bottom: 50rpx;
			background-color: #1534ce;
			background-size: cover;
			background-repeat: no-repeat;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			overflow: hidden;
			box-sizing: border-box;
			.progress{
				width: 100%;
				.bottom{
					width: calc(100% - 4rpx);
					margin-left: 2rpx;
					height: 14rpx;
					background-color: #fff;
					border: 2rpx solid #fff;
					border-radius: 8rpx;
					.value{
						// width: 80%;
						height: 100%;
						background-color: #0535d6;
						border-radius: 8rpx;
					}
				}
				.top{
					width: 100%;
					padding-top: 10rpx;
					height: 54rpx;
					line-height: 64rpx;
					.left{
						float: left;
						font-weight: light;
						font-size: 26rpx;
						color: #ffffff;
						text{
							font-size: 16rpx;
						}
					}
					.right{
						float: right;
						font-weight: bold;
						font-size: 26rpx;
						color: #ffffff;
					}
				}
			}
		}
	}
</style>
